package com.qf;

import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author sunyamei
 * @version V1.0
 * @Project javase2203
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/8/8 19:48
 */
@RequestMapping("/test")
@RestController
public class TestController {

    @Autowired
    private UserService userService;

    @Resource(name = "user1")
    private User user;

    //读取配置yml文件中的内容
    @Value("${aliyun.username}")
    private  String username;


    @Value("${aliyun.password}")
    private  String password;


    @RequestMapping("/hello")
    public  String hello(){
        System.out.println(username+password);
        return  "hello world"+user;
    }


    /**
     * 查询所有
     * @return
     */
    @RequestMapping("/list")
    public List<User> findAll(){
        List<User> list = userService.findAll();
        return  list;
    }


    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @RequestMapping("/byid")
    public  Object findById(Integer id){
        User user = userService.findById(1);
        return  user;
    }


    /**
     * 添加
     * @return
     */
    @RequestMapping("/add")
    public Object add(User user){
//        User user = new User();
        user.setName("冰冰");
        user.setPassword("123456");
        user.setSex("女");
        user.setBirthday(new Date());
        user.setRegistTime(new Date());
        userService.add(user);
        return  user;
    }

}
